<template>
	<a-modal
		v-model:visible="visible"
		:title="title"
		:width="800"
		:mask-closable="false"
		:destroy-on-close="true"
		@ok="handleOk"
		@cancel="handleClose"
	>
		<template v-if="checkItems.length>0">
			<template v-for="item in checkItems">
				<a-row :gutter="24">
					<a-col :span="24">
						<b>{{item.checkItem}}</b>
					</a-col>
					<a-col :span="20">
						{{item.checkDes}}
					</a-col>
					<a-col :span="4">
						<a-tag v-if="item.checkResult === 0" color="red">不合格</a-tag>
						<a-tag v-if="item.checkResult === 1" color="green">合格</a-tag>
					</a-col>
					<a-col :span="24">
						{{item.checkRemark}}
					</a-col>
					<a-col :span="24">
						<template v-if="item.checkFiles">
							<a-image-preview-group >
								<a-image :width="80" :height="80" :src="getFileUrl(fileId)" v-for="fileId in item.checkFiles.split(',')"/>
							</a-image-preview-group>
						</template>
					</a-col>
				</a-row>
				<a-divider/>
			</template>
		</template>
		<template v-else>
			<a-row :gutter="24">
				<a-col :span="24">
					无
				</a-col>
			</a-row>
		</template>
	</a-modal>
</template>

<script setup name="goodsLedgerCheckItems">
	// 弹窗是否打开
	import bizGoodsLedgerApi from "@/api/biz/bizGoodsLedgerApi";
	import sysConfig from '@/config/index'

	let visible = $ref(false)
	const emit = defineEmits({onBack: null})
	const checkItems = ref([])

	const title = ref('领用检查记录')


	// 打开弹框
	const onOpen = (ledgerId, checkType) => {
		visible = true
		if (checkType === 0) {
			title.value = '领用检查记录'
		}
		if (checkType === 1) {
			title.value = '归还检查记录'
		}
		bizGoodsLedgerApi.bizGoodsLedgerCheckList({
			ledgerId: ledgerId,
			checkType: checkType
		}).then((data) => {
			checkItems.value = data
		})
	}

	//确定
	const handleOk = () => {
		handleClose()
	}

	//关闭
	const handleClose = () => {
		visible = false
	}

	//获取附件完整地址
	const getFileUrl = (id) => {
		return sysConfig.API_URL + '/dev/file/download?id=' + id
	}
	defineExpose({
		onOpen
	})
</script>

<style scoped type="less">
	.checkItemLabel {
		ant-descriptions-item-label: 20%;
	}
</style>
